<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">

</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">





        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">审核</a>
        </script>

    </div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../js/axios.min.js"></script>
<script>

    var engineerProvince, engineerCity, engineerArea, engineerId;
    axios.defaults.withCredentials = true


    layui.use(['form', 'table','layarea'], function () {
        //引入layui集成的包
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            layarea = layui.layarea;




        axios.get('http://localhost:8080/order/getOrdersBy101', {
            withCredentials: true

        })
            .then(function (response) {
                // 请求成功的处理逻辑
                var tableData = response.data.data;
                // 定义每页显示的数量和当前页码
                var pageSize = 10; // 每页显示10条数据
                var currentPage = 1; // 当前页码为1

                // 计算需要显示的数据范围
                var startIndex = (currentPage - 1) * pageSize;
                var endIndex = startIndex + pageSize;

                // 提取需要显示的数据
                var currentPageData = tableData.slice(startIndex, endIndex);


                // 定义数据表格的配置项
                var tableConfig = {
                    elem: '#currentTableId',
                    data: tableData, // 设置完整的数据列表
                    page: true, // 开启分页
                    limit: pageSize, // 每页显示的数量
                    cols: [[
                        {field: 'userName', width: 80, title: '商家'},
                        {field: 'productType', width: 110, title: '产品型号', sort: true},
                        {field: 'engineerName', width: 110, title: '工程师'},
                        {field: 'orderClientphone', width: 150, title: '用户手机号',},
                        {field: 'orderDate', width: 110, title: '日期', sort: true},
                        {field: 'orderArea', width: 80, title: '区县'},
                        {field: 'orderAddress', width: 110, title: '详细地址',},
                        {field: 'orderTime', width: 110, title: '时间', templet: '#timeTpl', sort: true},
                        {field: 'orderPicture', width: 110, title: '图片',},
                        {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
                    ]],
                    // 设置初始排序
                    initSort: {
                        field: 'orderPriority',
                        type: 'desc' // 降序排列
                    }
                };

                // 渲染表格
                var tableInstance = table.render(tableConfig);

                // 监听分页切换事件
                table.on('page(currentTableFilter)', function(obj) {
                    // 更新当前页码
                    currentPage = obj.curr;

                    // 计算需要显示的数据范围
                    var startIndex = (currentPage - 1) * pageSize;
                    var endIndex = startIndex + pageSize;

                    // 提取需要显示的数据
                    var currentPageData = dataList.slice(startIndex, endIndex);

                    // 更新表格数据
                    tableInstance.reload({
                        data: currentPageData
                    });
                });


            })
            .catch(function (error) {
                console.log(document.cookie)
                // 请求失败的处理逻辑
                console.error(error);
            });


        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            var orderId = data.orderId;
            console.log(data);
            if (obj.event === 'edit') {
                layer.confirm('该订单是否有问题？', {
                    btn: ['是', '否'], // 自定义按钮文本
                    shadeClose: true
                }, function (index) {
                    // 在这里执行接单的逻辑
                    axios.get('http://localhost:8080/order/checkBy101/' + orderId + '/1', {
                        withCredentials: true
                    }).then(function (response) {
                        // 接单成功，显示成功提示信息
                        var output = response.data.code;
                        if(output === 0){
                            layer.msg("订单已退回订单池");
                            table.reload('currentTableId');
                        }
                    }).catch(function (error) {
                        // 接单失败，显示失败提示信息
                        layer.msg("发生错误，请稍后再试");
                        table.reload('currentTableId');
                    });

                    layer.close(index); // 关闭确认窗口
                }, function (index) {
                    axios.get('http://localhost:8080/order/checkBy101/' + orderId + '/2', {
                        withCredentials: true
                    }).then(function (response) {
                        // 接单成功，显示成功提示信息
                        var output = response.data.code;
                        if(output === 0){
                            layer.msg("订单正常完结");
                            table.reload('currentTableId');
                        }
                    }).catch(function (error) {
                        // 接单失败，显示失败提示信息
                        layer.msg("发生错误，请稍后再试");
                        table.reload('currentTableId');
                    });
                });
                return false;
            }
        });


    });

</script>
<script type="text/html" id="timeTpl">
    {{#  if(d.orderTime === 0){ }}
    上午
    {{#  } else if(d.orderTime === 1) { }}
    下午
    {{#  } else if(d.orderTime === 2) { }}
    晚上
    {{#  } }}
</script>

</body>
</html>